<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header">
    <style type="text/css">
        .menu {
            width: 250px;
            height: 100%;
            position: fixed;
            background-color: seagreen;
            -webkit-transition: all 1s;
            transition: all 1s;
            left: 0;
            z-index: 50;
            overflow-y: auto;
            padding-bottom: 100px;
        }

        .menu.closed {
            left: -250px;
        }

        #toggle {
            background-color: seagreen;
            height: 100%;
            min-height: 100%;
            width: 50px;
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0px;
            z-index: 25;
            -webkit-transition: all 0.7s ease;
            transition: all 0.7s ease;
        }

        #toggle:hover {
            cursor: pointer;
        }

        #toggle.closed {
            left: 0px;
            top: 0;
            bottom: 0;
            right: 0;
            width: 100%;
            height: 100%;
            opacity: 0.3;
        }

        .content {
            width: 100%;
            height: 100%;
            margin-left: 0px;
            -webkit-transition: all 0.4s;
            transition: all 0.4s;
        }

        .content.closed .text {
            -webkit-transform: translateX(80px);
            -ms-transform: translateX(80px);
            transform: translateX(80px);
        }

        .text {
            width: 60%;
            margin: auto;
            -webkit-transition: all 1s;
            transition: all 1s;
            margin-top: 80px;
            margin-bottom: 80px;
        }

        h1,
        h2 {
            color: #444;
        }

        p {
            color: #444;
        }

        p img {
            float: left;
            margin: 15px;
        }

        .menu ul {
            list-style-type: none;
            padding: 0;
            margin: 85px 0 0 40px;
            padding-right: 40px;
        }

        .menu ul li {
            color: floralwhite;
            font-size: 20px;
            margin: 0 0 5px 0;
            display: block;
            height: 40px;
            line-height: 40px;
            padding-left: 10px;
            -webkit-transition: all 0.3s;
            transition: all 0.3s;
        }

        .menu ul li:hover {
            background-color: #3bb16f;
            cursor: pointer;
        }

        #wrapper {
            height: 100%;
            min-height: 100%;
            position: fixed;
            overflow-y: auto;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }

        #wrapper.closed {
            position: fixed;
        }

        hr {
            border: none;
            height: 1px;
            background-color: seagreen;
            position: relative;
            width: 90%;
            margin-left: 0;
        }

        hr:before {
            content: "/";
            display: block;
            top: -8px;
            left: -5px;
            position: absolute;
            color: seagreen;
        }

        *::-moz-selection {
            background-color: #1b5233;
            color: floralwhite;
        }

        *::selection {
            background-color: #1b5233;
            color: floralwhite;
        }
    </style>
</head>
<link rel="stylesheet" th:href="@{/css/yw.css}">
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        工艺任务过程看板
    </h1>
    <a id="btn-tzrw" href="javascript:void(0);"
       class="btn btn-info pull-right" style="margin-right: 15px;margin-bottom: 15px"><span class="Bold">任务项编辑</span>
    </a>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="row"><br>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>项目编号：</label><label id="proCode" name="proCode" th:text="${craProQueryModel.code}"></label>
                            <input id="proId" name="proId" th:value="${craProQueryModel.id}" type="hidden">
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>项目名称：</label><label th:text="${craProQueryModel.name}"></label>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>项目数量：</label><label th:text="${craProQueryModel.num}"></label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>安装地点：</label><label th:text="${craProQueryModel.address}"></label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>需方：</label><label th:text="${craProQueryModel.demander}"></label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>分配科室：</label><label th:text="${setionNames}"></label>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="col-xs-12">
                        <div>
                            <table id="bootstrap-table"></table>
                        </div>
                    </div>
                </div>
                <br><br><br>
                <div class="box-body" style=" font-size: 16px; background-color: #EBF4F9; min-height: 450px;">
                    <div id="divRight" class="hidden" style="background-color: #FFFFFF; width: 30px;text-align: center;
                     border: solid 1px #eee; cursor: pointer; float: left; height: 450px; line-height: 450px; margin: auto 0px; border-radius: 2px; "
                         onclick="rightDiv();">
                        <i class="fa fa-caret-right" style="color: #3C8DBC; font-size: 20px;"></i>
                    </div>
                    <div class="box" id="divLeft"
                         style="width:13%; float: left; height: 100%; min-height: 450px; min-width: 170px;">
                        <div class="box-header"
                             style="height: 60px; line-height: 40px; vertical-align: middle; text-align: center; ">
                            <i class="fa fa-list" style="color: #333; cursor: pointer; line-height: 20px; "
                               onclick="initZonglanDiv()">&nbsp;&nbsp;&nbsp;任务明细</i>
                            <div style="background-color: #F8F8F8; width: 20px;text-align: center; border: solid 1px #eee; cursor: pointer; float: right; height: 40px; line-height: 40px; margin: auto 0px; "
                                 onclick="leftDiv();">
                                <i class="fa fa-caret-left" style="color: #3C8DBC; font-size: 18px;"></i>
                            </div>
                        </div>
                        <div class="box-body" style="border-top: 1px solid #EEEEEE;">
                            <div id="proStruct-tree" class="ztree"></div>
                        </div>
                    </div>

                    <div class="box" style="width:85%; float: left; margin-left: 1%; min-height: 450px;" id="contetDiv">
                        <div class="box-header">
                            <h4 id="jiegouTitle">工艺任务信息总览</h4>
                        </div>
                        <div id="topDiv" style="display: none;">
                            <div class="box-body">
                                <h4>工艺卡编制</h4>
                                <div>
                                    <table id="craft-table"
                                           style="table-layout: fixed;word-break:break-all; word-wrap:break-word;font-size:12px;"></table>
                                </div>
                            </div>
                        </div>
                        <div id="middleDiv" style="display: none;">
                            <div class="box-body">
                                <a class="btn btn-info pull-right"
                                   th:href="@{/craft/proQuery/outPage(proCode = ${craProQueryModel.code},reportType=3)}"
                                   target="_blank">查看详细</a>
                                <h4>原材料计划</h4>
                                <div>
                                    <table id="material-table"
                                           style="table-layout: fixed;word-break:break-all; word-wrap:break-word;font-size:12px;"></table>
                                </div>
                            </div>
                        </div>

                        <div id="lastDiv" style="display: none;">
                            <div class="box-body">
                                <a class="btn btn-info pull-right"
                                   th:href="@{/craft/proQuery/outPage(proCode = ${craProQueryModel.code},reportType=2)}"
                                   target="_blank">查看详细</a>
                                <h4>外协件计划</h4>
                                <div>
                                    <table id="outsourcing-table"
                                           style="table-layout: fixed;word-break:break-all; word-wrap:break-word;font-size:12px;"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!--任务状态修改模态框-->
<div class="modal fade" id="modal-update">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 id="modal-update-title" class="modal-title"></h4>
            </div>
            <div class="modal-body" style="padding-bottom: 0px;">
                <form id="editForm" class="form-horizontal">
                    <input id="deptIdEdit" type="hidden" name="deptId"/>
                    <input id="id" type="hidden" name="id"/>
                    <input id="proIdEdit" type="hidden" name="proId"/>
                    <input id="comTaskNameIdEdit" type="hidden" name="comTaskNameId"/>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">项目</label>
                        <div class="col-sm-10">
                            <input disabled style="width: 100%;" th:value="${craProQueryModel.name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">状态</label>
                        <div class="col-sm-10">
                            <select id="status" class="form-control" name="status">
                                <option value="1" selected>未开始</option>
                                <option value="2">执行中</option>
                                <option value="3">已完成</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">开始时间</label>
                        <div class="col-sm-10">
                            <input id="startTime" type="text" class="form-control datepicker" name="startTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">结束时间</label>
                        <div class="col-sm-10">
                            <input id="endTime" type="text" class="form-control datepicker" name="endTime"
                                   readonly="readonly" style="width: 100%;"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10">
                            <textarea id="remark" name="remark" rows="3" style="width: 100%;"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-update-cost">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--产品部分状态列表-->
<div class="modal fade" id="modal-part">
    <div class="modal-dialog" style="width: 1240px;">
        <div class="modal-content">
            <input id="comTaskNameIdMo" type="hidden">
            <input id="specialIdMo" type="hidden">
            <form id="editPartForm" class="form-horizontal">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">任务状态维护</h4>
                </div>

                <div class="modal-body">
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>项目编号：</label><label th:text="${craProQueryModel.code}"></label>
                        </div>
                    </div>
                    <div class="col-md-5">
                        <div class="form-group">
                            <label>项目名称：</label><label th:text="${craProQueryModel.name}"></label>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>专业：</label><label id="specialMo"></label>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group">
                            <label>任务类型：</label><label id="comTaskNameMo"></label>
                        </div>
                    </div>
                    <div class="row">
                        <table id="bootstrap-table-part"></table>
                    </div>
                    <div id="taskDownHead" class="row" style="margin-top: 20px;">
                        <div class="col-md-6 col-md-offset-2" >
                            <div class="box">
                                <div class="box-header">
                                    <h4>项目任务编辑</h4>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <input id="" name="id" type="hidden">
                                        <input type="hidden" name="proId">
                                        <input id="proPartId" type="hidden" name="proPartId"/>
                                        <input type="hidden" name="comTaskNameId"/>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">项目</label>
                                            <div class="col-md-9">
                                                <input disabled style="width: 100%;" th:value="${craProQueryModel.name}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">部分</label>
                                            <div class="col-md-9">
                                                <input disabled style="width: 100%;" name="proPart">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">状态</label>
                                            <div class="col-md-9">
                                                <select class="form-control" name="status">
                                                    <option value="1" selected>未开始</option>
                                                    <option value="2">执行中</option>
                                                    <option value="3">已完成</option>
                                                    <option value="4">不需要</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">开始时间</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control datepicker" name="startTime"
                                                       readonly="readonly" style="width: 100%;" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">结束时间</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control datepicker" name="endTime"
                                                       readonly="readonly" style="width: 100%;" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">备注</label>
                                            <div class="col-md-9">
                                                <textarea name="remark" rows="3" style="width: 100%;"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="box-footer">
                                    <button type="button" class="btn btn-info pull-right" id="btn_create">保存</button>
                                    <button type="button" class="btn btn-default pull-right" id="btn-taskDownCancel"
                                            style="margin-right: 15px;" onclick="cancelEdit()">
                                        <span class="Bold">取消</span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

<div th:include="include :: footer"></div>

<script th:inline="javascript">
    let typeName = ['', '外购件', '外协件', '原材料'];
    var statusName = ["", "未开始", "执行中", "已完成", "不需要"];
    var statusColor = ["", "", "#f39c12", "#00a65a", "#00acd6"];
    var classType = ["", " label-inverse", " label-warning", " label-success", " label-primary"];
    var classTypeYuanCaiLiao=["", " label-inverse", " label-warning", " label-warning", " bg-red", " label-success"];
    var statusNameYuanCaiLiao=["", "未提交", "已提交", "被驳回", "撤销", "审核通过"];
    // var tablePart;

    $("#toggle").click(function () {
        $(".menu").toggleClass("closed");
        $(this).toggleClass("closed");
        $(".content").toggleClass("closed");
        $("#wrapper").toggleClass("closed")
    });

    function rightDiv() {
        $("#divRight").addClass("hidden");
        $("#divLeft").removeClass("hidden");
        $("#contetDiv").css("width", "85%");
    }

    function leftDiv() {
        $("#divLeft").addClass("hidden");
        $("#divRight").removeClass("hidden");
        $("#contetDiv").css("width", "95%");
    }
    /** 任务页面查询*/
    $("#btn-tzrw").click(function(){
        let proCode = $("#proCode").text();
        var urlTzrw = ctx + "craft/proQuery/tzrwList?proCode="+proCode;
        window.open(urlTzrw,"_blank");
    })

    /**
     * 初始化时候就执行
     */
    function selectDetail(part, special) {
        $("#zonglanDiv").show();
        $("#topDiv").show();
        $("#middleDiv").show();
        $("#lastDiv").show();
        $("#contetDiv").show();
        var table1;
        /** 加载采集数据表格 */
        $('#craft-table').bootstrapTable('destroy');
        table1 = js.table.init({
            id: "craft-table",
            url: ctx + "craft/proQuery/detail/craft",
            queryData: {proCode: [[${craProQueryModel.code}]], special: special, part: part},
            // showColumns: false,
            showExport: false,
            pagination: false,
            // pageSize: 10,
            columns: [
                {

                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: "分类", field: 'reportType',
                    formatter: function (value) {
                        return '<span >工艺编制</span>';
                    }
                },
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "分配科室", field: 'deptName'},
                {title: "校对时间", field: 'verifyTime'},
                {title: "下发时间", field: 'notifyTime'},
                {title: "审批人", field: 'checkNames'}
            ]
        });
        var table2;
        /** 原料计划表格 */
        $('#outsourcing-table').bootstrapTable('destroy');
        table2 = js.table.init({
            id: "outsourcing-table",
            url: ctx + "craft/proQuery/detail/material",
            queryData: {proCode: [[${craProQueryModel.code}]], special: special, part: part},
            // queryData: {id: para},
            // showColumns: false,
            showExport: false,
            pagination: false,
            // pageSize: 10,
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: "分类", field: 'reportType',
                    formatter: function (value) {
                        return typeName[value];
                    }
                },
                {title: "类型", field: 'malType'},
                {title: "部分", field: 'part'},
                {
                    title: "提报类型", field: 'sheetType',
                    formatter: function (value) {
                        return value === 1 ? '提报单' : '变更单';
                    }
                },
                {
                    title: "提报状态", field: 'status',
                    formatter: function (value, row) {
                        return '<span class="badge '+ classTypeYuanCaiLiao[value] +'">'+statusNameYuanCaiLiao[value]+'</span>';
                    }
                },
                {title: "提报人", field: 'postName'},
                {title: "提报科室", field: 'branchName'},
                {title: "提报日期", field: 'commitTime'},
                {title: "批准时间", field: 'verifyTime'}
            ]
        });
        var table3;
        /** 外协计划表格 */
        $('#material-table').bootstrapTable('destroy');
        table3 = js.table.init({
            id: "material-table",
            url: ctx + "craft/proQuery/detail/outsourcing",
            queryData: {proCode: [[${craProQueryModel.code}]], special: special, part: part},
            // queryData: {id: para},
            // showColumns: false,
            showExport: false,
            pagination: false,
            // pageSize: 10,
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: "分类", field: 'reportType',
                    formatter: function (value) {
                        return typeName[value];
                    }
                },
                {title: "类型", field: 'malType'},
                {title: "部分", field: 'part'},
                {
                    title: "提报类型", field: 'sheetType',
                    formatter: function (value) {
                        return value === 1 ? '提报单' : '变更单';
                    }
                },
                {
                    title: "提报状态", field: 'status',
                    formatter: function (value, row) {

                        return '<span class="badge '+ classTypeYuanCaiLiao[value] +'">'+statusNameYuanCaiLiao[value]+'</span>';
                    }
                },
                {title: "提报人", field: 'postName'},
                {title: "提报科室", field: 'branchName'},
                {title: "提报日期", field: 'commitTime'},
                {title: "批准时间", field: 'verifyTime'}
            ]
        });
    }

    /** 加载左侧产品结构数据 */
    function queryProStruceTree() {
        let kk = [[${craProQueryModel.proId}]];
        proStructTree = js.tree.init({
            id: "proStruct-tree",
            async: {
                url: ctx + "craft/proQuery/proStruct/" + $("#proId").val(),
            },
            check: {
                enable: false,                                                 // 是否显示多选框
            },
            data: {
                key: {
                    name: "proName"        // 节点数据保存节点名称的属性名称
                }
            },
            onClick: zTreeOnClick,
            beforeClick: zTreeBeforeClick
        });

        /** 展开左侧产品结构数据 */
        setTimeout(function () {
            proStructTree.expandAll(true);
        }, 500);

        /** 左侧产品树节点点击事件 */
        function zTreeOnClick(event, treeId, treeNode) {

            var parentName = "";
            if (treeNode.getParentNode() != null) {
                parentName = treeNode.getParentNode().proName;
            }
            readData(treeNode.proName, parentName);
        };

        function zTreeBeforeClick() {
            return true;
        };

    };

    /**
     * 合并单元格
     * @param data 原始数据（在服务端完成排序）
     * @param fieldName 合并依据属性名称
     * @param spanFieldName 合并属性名称
     * @param colspan 合并列
     * @param target 目标表格对象
     */
    function mergeCells(data, fieldName, spanFieldName, colspan, target) {
        //声明一个map计算相同属性值在data对象出现的次数和
        var sortMap = {};
        for (var i = 0; i < data.rows.length; i++) {
            for (var prop in data.rows[i]) {
                if (prop == fieldName) {
                    var key = data.rows[i][prop]
                    if (sortMap.hasOwnProperty(key)) {
                        sortMap[key] = sortMap[key] * 1 + 1;
                    } else {
                        sortMap[key] = 1;
                    }
                    break;
                }
            }
        }
        var index = 0;
        for (var prop in sortMap) {
            var count = sortMap[prop] * 1;
            $(target).bootstrapTable('mergeCells', {
                index: index,
                field: spanFieldName,
                colspan: colspan,
                rowspan: count
            });
            index += count;
        }
    }

    $(function () {

        /** 项目任务进度 */
        table = js.table.init({
            url: ctx + "craft/proQuery/taskStatus",
            onLoadSuccess: function (data) {
                // mergeCells(data, "proId", "statusFour", 1, $('#bootstrap-table')); //合并单元格
            },
            showExport: false,
            pagination: false,
            queryData: {
                proId: $("#proId").val(),
            },
            columns: [
                // {title: "专业", field: 'special', width: 100},
                {
                    title: "工艺编制", field: 'craftStatus',
                    formatter: function (value, row) {
                        if (hasP('tec:proSproject:edit')) {

                            var actions = [];
                            actions.push('<a style="display: block;height: 100%;width: 100%;" href="javascript:void(0)" ' +
                                'onclick="editCostStatus(' + js.jsonStringify(row) + ',1)"><span class="badge '+ classType[value] +'">' + statusName[value] + '</span></a>');
                            return actions.join('');
                        }else {
                            return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';

                        }
                    }
                },
                {
                    title: "原材料计划"
                    , field: 'materialStatus',
                    formatter: function (value, row) {
                        var actions = [];
                        if (hasP('tec:proSproject:editBlanking')) {

                            actions.push('<a style="display: block;height: 100%;width: 100%;" shiro:hasPermission="tec:proSproject:editBlanking" href="javascript:void(0)" ' +
                                'onclick="editCostStatus(' + js.jsonStringify(row) + ',9)"><span class="badge '+ classType[value] +'">' + statusName[value] + '</span></span></a>');
                            return actions.join('');
                        }else {
                            return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        }
                    }
                },
                {
                    title: "外协件计划", field: 'outsourcingStatus',
                    formatter: function (value, row) {
                        var actions = [];
                        if (hasP('tec:proSproject:editAss')) {
                        actions.push('<a style="display: block;height: 100%;width: 100%;"  href="javascript:void(0)" ' +
                            'onclick="editCostStatus(' + js.jsonStringify(row) + ',10)"><span class="badge '+ classType[value] +'">' + statusName[value] + '</span></a>');
                        return actions.join('');
                        }else {
                            return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        }
                    }
                },
                // {title: "原材料计划完成数", field: 'statusTwo1'},
                {
                    title: "成本信息输出", field: 'costStatus',
                    formatter: function (value, row) {
                        if (hasP('tec:proSproject:edit')) {


                            var actions = [];
                            actions.push('<a style="display: block;height: 100%;width: 100%;" shiro:hasPermission="tec:proSproject:edit" href="javascript:void(0)" ' +
                                'onclick="editCostStatus(' + js.jsonStringify(row) + ',4)"><span class="badge '+ classType[value] +'">' + statusName[value] + '</span></a>');
                            return actions.join('');
                        }else {

                            return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                        }


                    }
                },
                // {title: "外协件计划完成数", field: 'statusThree1', width: 100}
            ]
        });
        queryProStruceTree();
        selectDetail("","");
    });

    /** 任务状态编辑模态框 */
    function editStatus(result, taskType) {

        // 取得任务节点信息
        js.post({
            url: ctx + "craft/proQuery/nodeStatus",
            data: {proId: result.proId,specialId:result.specialId, comTaskNameId: taskType},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    // 任务状态编辑模态框数据源绑定
                    bindEditForm(result, taskType, result.data);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    function editCostStatus(result, taskType) {
        debugger
        // 取得任务节点信息
        js.post({
            url: ctx + "craft/proQuery/costStatus",
            data: {proId: result.proId,comTaskNameId: taskType},
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    // 任务状态编辑模态框数据源绑定
                    bindEditForm(result, taskType, result.data);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 任务状态编辑模态框数据源绑定 */
    function bindEditForm(result, taskType, data) {
        debugger
        if (taskType == 1) {
            $("#modal-update-title").text("工艺编制状态编辑");
        }
        if (taskType == 9) {
            $("#modal-update-title").text("原材料计划状态编辑");
        }
        if (taskType == 10) {
            $("#modal-update-title").text("外协件计划状态编辑");
        }
        if (taskType == 4) {
            $("#modal-update-title").text("成本信息输出状态编辑");
        }
        // if (taskType == 4) {
        $("#id").val(data.rows[0].id);
            $("#proIdEdit").val(data.rows[0].proId);
            $("#comTaskNameIdEdit").val(taskType);
            $("#editForm").fillData(data.rows[0]);
            js.modal.open("modal-update");
        // } else if (taskType == 1||taskType==9||taskType==10) {
        //     $("#specialMo").text(data.rows[0].special);
        //     $("#specialIdMo").val(data.rows[0].specialId);
        //     $("#comTaskNameMo").text(data.rows[0].comTaskName);
        //     $("#comTaskNameIdMo").val(data.rows[0].comTaskNameId);
        //     initTablePart(data.rows[0].proId,data.rows[0].specialId,taskType);
        //     $("#taskDownHead").hide();
        //     js.modal.open("modal-part");
        // }
    }
    //成本信息录入任务状态保存
    $("#btn-update-cost").click(function () {
        //状态为已完成时，必须填写完成时间，不填写完成时间不能保存，不写完成时间无法反写销售系统完成时间，影响生产系统看板 完成时间 数据，修改时间2020/6/7 13:00:00
        var sta = $("#status").val();
        if (sta==3){

            let res = js.vd({
                id: 'editForm',
                notEmpty: ['endTime']
            })
            if (!res) {
                return;
            }
        }
        js.validSubmit({
            formId:"editForm",
            url:ctx+"craft/proQuery/costSave",
            data:new FormData($("#editForm")[0]),
            success:function (result) {
                if(result.type==web_status.SUCCESS){
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("modal-update");
                }else {
                    js.modal.warning(result.msg);
                }
            }
        });

    });
    /** 右侧列表加载 */
    function readData(paramType, parentName) {

        /** 左侧计划表单数据加载 */
        selectDetail(paramType, parentName);
    }
    var tablePart;
    /** 加载选中专业的状态列表 */
    function initTablePart(proId,specialId,taskType){
        $("#bootstrap-table-part").bootstrapTable('destroy');
        // 加载表格
        tablePart = js.table.init({
            url: ctx + "craft/proQuery/partList",
            id: "bootstrap-table-part",
            showExport: false,
            pagination: false,
            queryData: {
                proId: proId,
                specialId: specialId,
                comTaskNameId:taskType
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "部分", field: 'proPart'},
                {title: "工艺科室", field: 'deptName',
                formatter:function (value, row) {
                    if(row.comTaskNameId==9||row.comTaskNameId==10){
                        return "工艺二科";
                    }
                    return value;
                }},
                {title: "状态", field: 'status',
                    formatter: function (value, row) {
                        return statusName[value];
                    },
                    cellStyle: function (value) {
                        return {css: {"background-color": statusColor[value]}}
                    }
                },
                {title: "开始时间", field: 'startTime'},
                {title: "结束时间", field: 'endTime'},
                {title: "备注", field: 'remark'},
                // {title: "编辑科室", field: 'deptName'},
                {
                    title: "操作", width: 100,
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditPart(' + js.jsonStringify(row) + ')"> 编辑</a> ');
                        return actions.join('');
                    }
                }
            ]
        });
    }
    /**
     * 取消
     */
    function cancelEdit() {
        $("#taskDownHead").hide();
    }
    /** 打开编辑模态框（部分状态） */
    function openEditPart(result) {
        $("#taskDownHead").show();
        $("#editPartForm").fillData(result);
    }
    /** 保存项目部分状态编辑 */
    $("#btn_create").click(function () {

        if ($("#proPartId").val() == ""){
            js.modal.warning("请先选择要编辑的部分！");
            return;
        }
        js.validSubmit({
            formId: "editPartForm",
            url: ctx + "craft/proQuery/editTaskStatus",
            data: new FormData($("#editPartForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#taskDownHead").hide();
                    js.reset("editPartForm");
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    // 重新加载项目部分列表
                    js.table.destroy(tablePart);
                    initTablePart($("#proId").val(),$("#specialIdMo").val(),$("#comTaskNameIdMo").val());
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    });
</script>


